<template>
  <div style="background: #fff;">
    <p class="y_c_input1">
      <input type="text" placeholder="输入患者姓名、基本信息查询" v-model="patientKey">
      <i class="iconfont icon-sousuo" @click="getPatientlist(1)"></i>
    </p>
    <scroller class="shoplist_container1" :onRefresh="refresh" :onInfinite="infinite">
      <ul>
        <router-link
          v-for="item in list"
          :key="item.id"
          :to="{name:'curePatient',query:{patientInfo:JSON.stringify(item)}}"
          tag="li"
        >
          <div class="shop_right1"
            @click="readMg(item)"
          >
            <p class="shop_name1" style="display:inline-block">姓名：{{item.PATNAME}}  性别：{{item.PATSEX}}  年龄：{{item.PATNL}}</p><mt-badge v-show="Number(item.NEWMSG) > 0" type="warning" size="small" style="float:right;margin-right:1.6rem"
              color="#26a2ff"
            >{{item.NEWMSG}}</mt-badge>
            <p style="color:rgb(159, 159, 159);">最后就诊时间：{{item.MSGTIME}}</p>
          </div>
        </router-link>
      </ul>
    </scroller>
    <backTop></backTop>
  </div>
</template>
<script>
import backTop from '~/components/pagetwo/backTop.vue';

export default {
  data() {
    return {
      DATAOBJ: {},
      list: [],
      ts: this.newStore(),
      page: 0,
      patientKey: '',
    };
  },
  created() {
    document.title = '我的患者';
  },
  components: {
    backTop,
  },
  methods: {
    refresh(done) {
      this.page = 0;
      this.getPatientlist(1, done);
    },
    infinite(done) {
      setTimeout(() => {
        this.page += 1;
        this.getPatientlist(this.page, done);
      }, 500);
    },
    getPatientlist(page, fn) {
      const req = JSON.stringify({
        OTRequest: {
          VERSION: '1.0',
          TN: 'F27.APP.01.16',
          CLIENTID: 'YLAPP',
          RYBID: 'DOCTOR',
          TOKEN: `${sessionStorage.getItem('rybToken')}`,
          DATA: {
            rowsperpage: '10',
            page: `${this.page}`,
            keywords: this.patientKey,
          },
        },
      });

      this.spost(this.ts, '/doctor/AppMainServlet.ap', {
        '': req,
      }).then((ts) => {
        if (ts.d.DATAOBJ.DATA.length < 1) {
          this.page = 0;
          fn(true);
          return;
        } else if (fn) {
          fn();
        }
        if (page == 1) {
          this.list = ts.d.DATAOBJ.DATA;
        } else {
          this.list = this.list.concat(ts.d.DATAOBJ.DATA);
        }
      });
    },
    readMg(item) {
      const req = JSON.stringify({
        OTRequest: {
          VERSION: '1.0',
          TN: 'F27.APP.01.30',
          CLIENTID: 'YLAPP',
          RYBID: 'DOCTOR',
          TOKEN: `${sessionStorage.getItem('rybToken')}`,
          DATA: {
            patid: `${item.PATID}`,
          },
        },
      });

      this.spost(this.ts, '/doctor/AppMainServlet.ap', {
        '': req,
      }).then((ts) => {
        console.log(JSON.stringify(ts.d.DATAOBJ));
      });
    },
  },
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
.shoplist_container1 {
  margin-top: 5.6rem;
  background: #f8f9fa;
  padding-top: 0.5rem;
}
.shoplist_container1 ul li {
  margin-bottom: 0.5rem;
}
.shop_right1 {
  padding: 0.4rem 1rem 0 1rem;
  /* border-bottom: 1px solid #f1f1f1; */
  width: 97%;
  margin: 0 auto;
  background: #fff; /* rgba(241, 241, 241, 0.41); */
  border-radius: 0.2rem;
  box-shadow: 0rem 0rem 1px 0px #ccc;
}
.shop_right1 p {
  margin: 0rem;
  line-height: 2rem;
  font-size: 0.9rem;
}
.shop_message1 {
  word-break: break-all;
}
.shop_span {
  float: right;
  color: #3190e8;
}
.patient_time {
  font-size: 0.8rem;
  color: #3190e8;
  float: right;
}
.y_c_input1 input {
  width: 100%;
  border: none;
  padding: 0.5rem 0;
  font-size: 0.9rem;
  font-family: "Microsoft Yahei";
  padding-right: 2rem;
  background: rgba(241, 241, 241, 0.41);
  text-indent: 0.3rem;
  outline: none;
  border-radius: 0.2rem;
  box-shadow: 0rem 0rem 1px 0px #ccc;
}
.y_c_input1 {
  position: relative;
  width: 97%;
  margin: 0.3rem auto;
  margin-top: 3rem;
  background: #fff;
}
.y_c_input1 i {
  position: absolute;
  top: 0;
  right: 2%;
  z-index: 500;
  font-size: 1.4rem;
  color: #3190e8;
  display: inline-block;
}
</style>

